package com.qf.team2.netdisc.admin.controller;

import com.qf.team2.netdisc.admin.service.AdminManageService;
import com.qf.team2.netdisc.common.base.BaseController;
import com.qf.team2.netdisc.common.pojo.vo.RespResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 管理员操作业务接口
 *
 * @author Simon_Wong
 * @since 2021/5/20 19:53
 */

@Controller
@RequestMapping("/admin")
@Api(tags = "管理员操作业务接口")
public class AdminManageController extends BaseController<Object> {

    @Autowired
    private AdminManageService adminManageService;

    @SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
    @ResponseBody
    @RequestMapping(value = "/setUserVIP", method = RequestMethod.POST)
    @ApiOperation("设置用户为VIP")
    @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "Integer")
    public RespResultVO<Object> setUserVIP(@RequestBody Integer userId) {
        adminManageService.setVIPByUserId(userId);
        return successResp(null, "设置成功");
    }

    @SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
    @ResponseBody
    @RequestMapping(value = "/setAllUserVIP", method = RequestMethod.POST)
    @ApiOperation("设置选中的用户为VIP")
    @ApiImplicitParam(name = "userIds", value = "选中的用户id", required = true, dataType = "Integer", allowMultiple = true)
    public RespResultVO<Object> setAllUserVIP(@RequestBody Integer... userIds) {
        List<Integer> failedList = adminManageService.setAllUserVIP(userIds);
        if (failedList.size() == userIds.length) {
            return businessResp("设置失败");
        }
        if (!failedList.isEmpty()) {
            return businessRespWithData(failedList, "部分设置失败，请检查数据");
        }

        return successResp(null, "设置成功");
    }

    @ResponseBody
    @RequestMapping(value = "/setDocumentInvisible", method = RequestMethod.POST)
    @ApiOperation("设置文件对用户端不可见")
    @ApiImplicitParam(name = "documentId", value = "文件id", required = true, dataType = "Integer")
    public RespResultVO<Object> setDocumentInvisible(@RequestBody Integer documentId) {
        adminManageService.setDocumentDeleted(documentId);
        return successResp(null, "文件删除成功");
    }

    @ResponseBody
    @RequestMapping(value = "/setAllDocumentInvisible", method = RequestMethod.POST)
    @ApiOperation("设置选中的文件对用户端不可见")
    @ApiImplicitParam(name = "documentIds", value = "选中的文件id", required = true, dataType = "List<Integer>")
    public RespResultVO<Object> setAllDocumentInvisible(@RequestBody Integer... documentIds) {
        List<Integer> failedList = adminManageService.setAllDocumentDeleted(documentIds);
        if (failedList.size() == documentIds.length) {
            return businessResp("设置失败");
        }
        if (!failedList.isEmpty()) {
            return businessRespWithData(failedList, "部分设置失败，请检查数据");
        }

        return successResp(null, "设置成功");
    }

    @ResponseBody
    @RequestMapping(value = "/setUserCommon", method = RequestMethod.POST)
    @ApiOperation("设置用户为普通用户")
    @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "Integer")
    public RespResultVO<Object> setUserCommon(@RequestBody Integer userId) {
        adminManageService.setCommonByUserId(userId);
        return successResp(null, "设置成功");
    }

    @ResponseBody
    @RequestMapping(value = "/setAllUserCommon", method = RequestMethod.POST)
    @ApiOperation("设置选中的用户为普通用户")
    @ApiImplicitParam(name = "userIds", value = "选中的用户id", required = true, dataType = "Integer", allowMultiple = true)
    public RespResultVO<Object> setAllUserCommon(@RequestBody Integer... userIds) {
        List<Integer> failedList = adminManageService.setAllUserCommon(userIds);
        if (failedList.size() == userIds.length) {
            return businessResp("设置失败");
        }
        if (!failedList.isEmpty()) {
            return businessRespWithData(failedList, "部分设置失败，请检查数据");
        }

        return successResp(null, "设置成功");
    }

    @ResponseBody
    @RequestMapping(value = "/setDocumentVisible", method = RequestMethod.POST)
    @ApiOperation("设置文件对用户端可见")
    @ApiImplicitParam(name = "documentId", value = "文件id", required = true, dataType = "Integer")
    public RespResultVO<Object> setDocumentVisible(@RequestBody Integer documentId) {
        adminManageService.setDocumentUndeleted(documentId);
        return successResp(null, "文件恢复成功");
    }

    @ResponseBody
    @RequestMapping(value = "/setAllDocumentVisible", method = RequestMethod.POST)
    @ApiOperation("设置选中的文件对用户端可见")
    @ApiImplicitParam(name = "documentIds", value = "选中的文件id", required = true, dataType = "List<Integer>")
    public RespResultVO<Object> setAllDocumentVisible(@RequestBody Integer... documentIds) {
            List<Integer> failedList = adminManageService.setAllDocumentUndeleted(documentIds);
        if (failedList.size() == documentIds.length) {
            return businessResp("设置失败");
        }
        if (!failedList.isEmpty()) {
            return businessRespWithData(failedList, "部分设置失败，请检查数据");
        }

        return successResp(null, "设置成功");
    }

    @ResponseBody
    @RequestMapping(value = "/setAllUserInvisible", method = RequestMethod.POST)
    @ApiOperation("设置选中的用户对用户端不可见")
    @ApiImplicitParam(name = "userIds", value = "选中的用户id", required = true, dataType = "List<Integer>")
    public RespResultVO<Object> setAllUserInvisible(@RequestBody Integer... userIds) {
            List<Integer> failedList = adminManageService.setAllUserDeleted(userIds);
        if (failedList.size() == userIds.length) {
            return businessResp("设置失败");
        }
        if (!failedList.isEmpty()) {
            return businessRespWithData(failedList, "部分设置失败，请检查数据");
        }

        return successResp(null, "设置成功");
    }

    @ResponseBody
    @RequestMapping(value = "/setAllUserVisible", method = RequestMethod.POST)
    @ApiOperation("设置选中的用户对用户端可见")
    @ApiImplicitParam(name = "userIds", value = "选中的用户id", required = true, dataType = "List<Integer>")
    public RespResultVO<Object> setAllUserVisible(@RequestBody Integer... userIds) {
        List<Integer> failedList = adminManageService.setAllUserUndeleted(userIds);
        if (failedList.size() == userIds.length) {
            return businessResp("设置失败");
        }
        if (!failedList.isEmpty()) {
            return businessRespWithData(failedList, "部分设置失败，请检查数据");
        }

        return successResp(null, "设置成功");
    }
}
